<?php
class Product extends Frontend_Controller{
	public function __construct(){
		parent::__construct();
		$this->load->Model(array("Mproduct"));
	}

	public function detail(){
		$url = $this->uri->segment(2);
		$arrUrl = explode('-',$url);
		$cache_id = $id = $arrUrl[0];
		$data = array();
		if (is_numeric($id) && $id != 0) {
			$data['list'] = $this->Mproduct->showListProduct();
			$data['detail'] = $this->Mproduct->showDetailProduct($id);
			if(empty($data['detail'])){
				$this->show404();
			}else{
				$data['type'] = 'product';
				$data['image'] = base_url().$data['detail']['thumb'];
				$data['url'] = base_url().'san-pham/'.$data['detail']['id'].'-'.$data['detail']['url'].'.html';
				
				$title = trim($data['detail']['title']);
				$title = strip_tags($title);
				$data['title'] = $title;
				
				$data['keywords'] = trim($data['detail']['keywords']);
				$data['description'] = trim($data['detail']['description']);

				$this->parser->parse("product/detail.tpl", $cache_id, $data);
			}
		}else{
			$this->show404();
		}
	}
}